<template>
	<view class="currency-container">
		<view class="header-container">
			<view class="currency-number">{{userInfo.xuewang}}</view>
			<view class="currency-detail"><text>雪王币明细></text><text>雪王币规则></text></view>
		</view>
		<view class="currency-main">
			<view class="alarm-container">
				<image src="../../static/notice.png" mode="widthFix"></image>
				<text>您有</text>
				<text class="red-color">{{766}}</text>
				<text>个雪王币即将过期，请尽快兑换使用</text>
			</view>
			<!-- 热门兑换 -->
			<view class="hot-container">
				<view class="common-title">
					<text class="left-words">热门兑换</text>
					<text class="right-words">查看更多></text>
				</view>
				<view class="hot-main">
					<view class="hot-common-block">
						<view class="image-container">
							<image src="../../static/zhe.png" mode="widthFix"></image>
						</view>
						<view class="hot-common-bottom">
							<view class="hot-bottom-title"><text>88折饮品券</text><text class="pink-color">88冰雪王专享</text></view>
							<view class="hot-bottom-desc"><text class="left-number">588 </text><text class="gray-color">雪王币 </text><text class="right-button">去兑换 </text></view>
						</view>
					</view>
					<view class="hot-common-block">
						<view class="image-container">
							<image src="../../static/bi.png" mode="widthFix"></image>
						</view>
						<view class="hot-common-bottom">
							<view class="hot-bottom-title"><text>1元饮品券</text></view>
							<view class="hot-bottom-desc"><text class="left-number">298 </text><text class="gray-color">雪王币 </text><text class="right-button">去兑换 </text></view>
						</view>
					</view>
				</view>
			</view>
			<!-- 日常任务 -->
			<view class="hot-container">
				<view class="common-title">
					<text class="left-words">日常任务</text>
				</view>
				<view class="job-container">
					<view class="job-container-block">
						<view class="left-block">
							<image class="left-icon" src="../../static/bi.png"></image>
							<view class="center-block">
								<view class="center-block-title">每日签到</view>
								<view class="center-block-desc"><image src="../../static/right.png"></image>+5雪王币</view>
							</view>
						</view>
						<text v-if="signinFlag" class="right-block">已完成</text>
						<text v-if="!signinFlag" class="sign-button" @click="signClick">签到</text>
						
					</view>
					<view class="job-container-block">
						<view class="left-block">
							<image class="left-icon" src="../../static/quan.png"></image>
							<view class="center-block">
								<view class="center-block-title">完成订单</view>
								<view class="center-block-desc"><image src="../../static/right.png"></image> +10雪王币 (每实付1元)</view>
							</view>
						</view>
						<text  class="right-button" @click="jumpIndex">去下单</text>
					</view>
				</view>
			</view>
			<!-- 新手任务 -->
			<view class="hot-container">
				<view class="common-title">
					<text class="left-words">新手任务</text>
				</view>
				<view class="job-container ">
					<view class="job-container-block new-job">
						<view class="left-block">
							<image class="left-icon" src="../../static/quan.png"></image>
							<view class="center-block">
								<view class="center-block-title">完成首单</view>
								<view class="center-block-desc"><image src="../../static/right.png"></image>举+20雪王币 (每实付1元)</view>
							</view>
						</view>
						<text v-if="signNew" class="right-block" >已完成</text>
						<text v-if="!signNew" class="right-button" @click="jumpIndex">去下单</text>
						<!-- <text v-if="signOrderFlag" class="right-block">已完成</text>
						<text v-if="!signOrderFlag" class="right-button" @click="jumpIndex">去下单</text> -->
					</view>
					<view class="li-nav" >
						<image class="left-icon" src="../../static/jiameng.png"></image>
						<text class="title-words">蜜雪冰城APP</text>
						<view class="right-block"><text>下载APP体验</text><image class="right-icon" src="../../static/right.png"></image></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {baseUrl} from "../../utils/request.js";
	export default {
		data() {
			return {
				signinFlag:false,//是否点击签到
				countNumber:938,//币数量
				signOrderFlag:false,
				signNew:false,
				userInfo:getApp().globalData.userInfo
			}
		},
		onShow() {
			// this.countNumber = this.userInfo.xuewang
			// this.signinFlagToday()
			this.getAllOrders(1)
			this.getUserInfo()
		},
		methods: {
			
			backof() {
			    uni.navigateBack({
			        delta: 1
			    });
			},
			getUserInfo(){
				uni.request({
				    // url: 'https://www.fastmock.site/mock/68c3c014a443685834fb331ec92e7e9d/show/shop',
					method:"get",
				    url: baseUrl+'/mixuebingcheng/user/'+getApp().globalData.userInfo.id,
					// data:this.userInfo,
				    success: (res) => {
				        console.log(res);
						getApp().globalData.userInfo = res.data.data
						this.userInfo = getApp().globalData.userInfo
						this.signinFlagToday()
				    }
				});
			},
			getAllOrders(orderStatus) {
				console.log("orderStatus")
				uni.request({
				  method:"GET",
			      url: baseUrl + `/mixuebingcheng/test/list`,
				  data:{
					status: orderStatus,
					userId: getApp().globalData.userInfo.id
				  },
			      success: (res) => {
					  if(res.data.code==200){
						  this.signNew = res.data.total!=0;
					  }
					  console.log('signNew',res)
					  console.log('signNew',this.signNew)
			      }
			  });
			},
			isOrderToday(){
				// uni.request({
				//     // url: 'https://www.fastmock.site/mock/68c3c014a443685834fb331ec92e7e9d/show/shop',
				// 	method:"get",
				//     url: baseUrl+'/mixuebingcheng/user/'+this.userInfo.id,
				// 	data:this.userInfo,
				//     success: (res) => {
				//         console.log(res);
				// 		getApp().globalData.userInfo = res.data.data
				// 		this.signinFlagToday()
				//     }
				// });
			},
			signinFlagToday(){
				
				// 获取当前日期
				const today = new Date();
				 
				// 获取要判断的日期
				const dateToCheck = new Date(getApp().globalData.userInfo.qiandao);
				 
				// 将日期转换为年月日的字符串形式
				const todayStr = today.toISOString().slice(0, 10);
				const dateToCheckStr = dateToCheck.toISOString().slice(0, 10);
				 
				// 判断两个日期的字符串形式是否相同
				const isToday = todayStr === dateToCheckStr;
				this.signinFlag = isToday;
				// console.log("this.userInfo.qiandao")
				// console.log('isToday',isToday)
				// console.log(this.userInfo)
			},
			//点击签到
			signClick(){
				// this.signinFlag=true;
				this.countNumber=this.countNumber+5
				this.userInfo.xuewang += 5
				uni.request({
				    // url: 'https://www.fastmock.site/mock/68c3c014a443685834fb331ec92e7e9d/show/shop',
					method:"PUT",
				    url: baseUrl+'/mixuebingcheng/user/xuewang',
					data:this.userInfo,
				    success: (res) => {
				        // console.log(res);
						uni.request({
						    // url: 'https://www.fastmock.site/mock/68c3c014a443685834fb331ec92e7e9d/show/shop',
							method:"get",
						    url: baseUrl+'/mixuebingcheng/user/'+this.userInfo.id,
							// data:this.userInfo,
						    success: (res) => {
						        console.log(res);
								getApp().globalData.userInfo = res.data.data
								this.signinFlagToday()
						    }
						});
				    }
				});
			},
			/**
			 * 点击去下单
			 */
			jumpIndex(){
				console.log("sd")
				uni.switchTab({
					url: '/pages/newoder/newoder'
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
.currency-container{
	color: rgb(51, 51, 51);
	.header-container{
		height:180upx ;
		background-color: rgb(229, 0, 20);
		padding: 20upx;
		box-sizing: border-box;
		.currency-number{
			color: #fff;
			font-size: 50upx;
			margin-top: 40upx;
			font-weight:bold;
		}
		.currency-detail{
			color: #fff;
			font-size: 20upx;
			margin-top: 10upx;
		}
		
	}
	.currency-main{
		background-color: rgb(247, 247, 247);
		padding: 20upx;
		box-sizing: border-box;
		border-radius: 20upx 0;
		.alarm-container{
			height: 40upx;
			line-height: 40upx;
			border-radius: 10upx;
			background-color: #fff;
			color: #999;
			padding-left: 20upx;
			font-size: 20upx;
			image{
				width: 20upx;
				margin-top: 10upx;
				margin-right: 10upx;
			}
			text{
				display: inline-block;
				height: 40upx;
				line-height: 40upx;
				vertical-align: top;
			}
			.red-color{
				color: #d81e06;
			}
		}
		.common-title{
			color: #333;
			font-size: 26upx;
			padding:10upx 0 ;
			font-weight: bold;
			margin-top: 10upx;
			.right-words{
				color:  #d81e06;
				float: right;
				font-size: 20upx;
				font-weight: normal
			};
			
		}
			
		.hot-main{
			margin-left: 10px;
			font-size: 0;
			.hot-common-block{
				width: calc(50% - 25upx);
				display: inline-block;
				background-color: rgb(255, 225, 225);
				border-radius: 20upx;
				.image-container{
					height: 160upx !important;
					padding: 20upx;
					box-sizing: border-box;
					image{
						margin-left: 15px;
						width: 80%;
						height: 120upx !important;
					}
				}

				.hot-common-bottom{
					background-color: #fff;
					padding: 20upx;
						
					.hot-bottom-title{
						font-size: 24upx;
						.pink-color{
							padding: 0 8upx;
							background-color:rgb(245, 138, 138) ;
							color: #fff;
							font-size: 18upx;
							border-radius: 10upx;
							margin-left: 10upx;
						}
					}
					.hot-bottom-desc{
						color: #d81e06;
						font-size: 26upx;
						margin-top: 10upx;
						.gray-color{
							color: #999;
							font-size: 20upx;
							margin-left: 20upx;
						}
						.right-button{
							float: right;
							background-color: #d81e06;
							color: #fff;
							font-size: 24upx;
							border-radius: 10upx;
							padding: 5upx 10upx;
						}

					}
				}
			}
			.hot-common-block:first-child{
				margin-right: 20upx;
			}
		}
		.job-container{
			.job-container-block{
				padding:20upx 20upx ;
				box-sizing: border-box;
				border-radius: 20upx;
				margin-top: 30upx;
				.left-block{
					display: inline-block;
					.left-icon{
						width: 100upx;
						height: 100upx;
					}
					.center-block{
						display: inline-block;
						vertical-align: top;
						width: 280upx;
						height: 100upx;
						.center-block-title{
							margin-top:10upx;
							font-size: 26upx;
							font-weight: bold;
						}
						
						.center-block-desc{
							color: #999;
							font-size: 20upx;
							margin-top:20upx;
							image{
								width: 20upx;
								height: 20upx;
							}
						}
					}
				}
				.right-block{
					display: inline-block;
					float: right;
					font-weight: bold;
					color: #d81e06;
					font-size: 24upx;
					margin-top: 30upx;
				}
				.right-button{
					float: right;
					background-color: #fff;
					color: rgb(254, 157, 6);
					font-size: 24upx;
					border-radius: 10upx;
					padding: 5upx 10upx;
					margin-top: 30upx;
				}
				.sign-button{
					float: right;
					background-color: #fff;
					color: #d81e06;
					font-size: 24upx;
					border-radius: 10upx;
					padding: 5upx 10upx;
					margin-top: 30upx;
				}
			}
			.job-container-block:nth-child(1){
				background-color: rgb(255, 235, 235);
			}
			.job-container-block:nth-child(2){
				background-color: rgb(254, 243, 221);
			}
			.new-job{
				background-color: rgb(232, 230, 251) !important;
				.right-block{
					display: inline-block;
					float: right;
					font-weight: bold;
					color: rgb(101, 94, 218) !important;
					font-size: 24upx;
					margin-top: 30upx;
				}
			}
			.li-nav{
				padding:20upx 20upx ;
				box-sizing: border-box;
				border-radius: 20upx;
				background-color: #fff;
				margin-top: 30upx;
				.left-icon{
					width: 40upx;
					height: 40upx;
				}
				.title-words{
					display: inline-block;
					color: rgb(51, 51, 51);
					height: 40upx;
					line-height: 40upx;
					vertical-align: top;
					margin-left: 20upx;
				}
				.right-block{
					float: right;
					color: #999;
					font-size: 24upx;
					.right-icon{
						width: 24upx;
						height: 24upx;
					}
				}
				
			}
		}
	}

}
</style>
